<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/view/include/inc.jsp"%>
<!DOCTYPE html >
<html>
<head>
<%@ include file="/WEB-INF/view/jQgrid.jsp"%>
<link type="text/css" rel="stylesheet" href="<%=contextPath %>/static/bootstrap-fileinput/css/fileinput.css" />
<script type="text/javascript" src="<%=contextPath %>/static/bootstrap-fileinput/js/fileinput.js"></script>
<script type="text/javascript" src="<%=contextPath %>/static/bootstrap-fileinput/js/locales/zh.js"></script>
</head>
<body style="background-color: white;" class="gray-bg">
	<div class="ibox-content">
		<form class="form-horizontal m-t " id="signupForm" method="post" enctype="multipart/form-data">
		    <input type="hidden" name="id" id="id" value="${taskManager.id }" /> <!--id  -->
		    <div class="form-group">
				<label class="col-sm-3 control-label"> 完成进度 ：</label>
				<div class="col-sm-8">
					<select class="form-control" name="plan">
						<c:forEach items="${fns:getDictList('task_progress')}"
							var="temp1">
							<option value="${temp1.value }">${temp1.valueName }</option>
						</c:forEach>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">附件：</label>
				<div class="col-sm-8">
					<input type="hidden" id="fileNames1" name="fileNames" />
					<input type="file" name="file" id="fileNames" multiple accept="image/*">
					<p class="help-block"><i class="icon-info-sign"></i>支持图片上传，最大数量5个，图片大小不能超过5M</p>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label"> 备注 ：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="remark" name="remark" value="${taskManager.remark}"/>
				</div>
			</div>
			<div class="form-group" style="text-align: center;">
				<div class="col-sm-12">
					<button class="btn btn-primary" type="button" id="sub">提交</button>
				</div>
			</div>
		</form>
	</div>


	<script>
    $(function () {
    	initFileInput("fileNames");
        $("#sub").click(function () {
        	//批量验证表单非空
			//调用方式
        	var arr=new Array(
        	  new Array('plan','完成进度未选择!')
        	)
       	    for(var i=0;i<arr.length;i++){
        	    if($("#"+arr[i][0]).val()==''){
        		    $("#"+arr[i][0]).tips({
	  					side:3,
	  		            msg:arr[i][1],
	  		            bg:'#AE81FF',
	  		            time:1
  		            });
        		    $("#"+arr[i][0]).focus();
  				    return;
  			    }
       	    }
            $("#signupForm").ajaxSubmit({
                url: '<%=contextPath%>/taskManager/progress',
					type : 'post',
					dataType : "json",
					success : function(data) {
						if (data.code == 200) {
							swal({
								title : data.message,
								type : "success",
								showCancelButton : false,
								confirmButtonText : "确定",
								animation : "slide-from-bottom",
								closeOnConfirm : true
							}, function() {
								top.Dialog.close();
							});
						} else {
							swal("错误", data.message, "error");
						}
					}
				});

			});
		});
    function initFileInput(ctrlName) {
        var control = $('#' + ctrlName);
        var picUrl = '${taskManager.fileNames}';
        var picArr = new Array(); 
    	var picview = new Array(); 
    	picArr = picUrl.split(","); 
    	for(var i = 0;i<picArr.length;i++){
    		var temppic = picArr[i];
    		if(temppic!=""){
        		picview[i] = '<img src="<%=contextPath%>'+temppic+'" class="file-preview-image" style="max-width:100%;max-height:100%">';
    		}
    	} 
    	var picurl="";
    	var preConfigList =new Array();
    	var id = $("#id").val();
    		var array_element = ''; 
    		var tjson = {caption: array_element, // 展示的文件名 
    		width: '120px', 
    		url: '<%=contextPath%>/taskManager/deletePic', // 删除url 
    		key: array_element.id, // 删除是Ajax向后台传递的参数 
    		extra: {id: id,vediourl:array_element} 
    		}; 
    	preConfigList[0] = tjson; 
        control.fileinput({
        language : 'zh',
        uploadUrl : "<%=contextPath%>/upload/insert",
        allowedFileExtensions: ['jpg', 'gif', 'png'],//接收的文件后缀
        uploadAsync: true, //默认异步上传
        showUpload: false, //是否显示上传按钮
        showRemove : false, //显示移除按钮
        showPreview : true, //是否显示预览
        showCaption: false,//是否显示标题
        browseClass: "btn btn-primary", //按钮样式
        dropZoneEnabled: false,//是否显示拖拽区域
        maxFileSize : 5000,
        maxFileCount: 5, //表示允许同时上传的最大文件个数
        enctype: 'multipart/form-data',
        validateInitialCount:true,
        previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
        msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！",
        initialPreview: picview,
        initialPreviewConfig: preConfigList,
    }).on('filebatchselected', function (event, files) {//选中文件事件  
        $(this).fileinput("upload");  
    }).on("fileuploaded", function(e, data) {
        var res = data.response;
        picurl += res.success+",";
        var num=1;
        $('#' + ctrlName+num).attr("value", picurl);
    })
    }
	</script>
</body>
</html>